<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="iconfont icon-jianhao" v-if="food.count" @click.stop="updateFoodCount(false)"></div>
    </transition>
    <div class="cart-count" v-if="food.count">{{food.count}}</div>
    <div class="iconfont icon-hao" @click.stop="updateFoodCount(true)"></div>
  </div>
</template>

<script>
export default {
  name: 'CartControl',
  props: {
    food: Object
  },
  methods: {
    updateFoodCount (isAdd) {
      this.$store.dispatch('updateFoodCount', {isAdd, food: this.food})
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "../../common/stylus/mixins.styl"
  .cartcontrol
    font-size: 0
    .cart-decrease
      display: inline-block
      padding: 6px
      line-height: 24px
      font-size: 24px
      color: rgb(0, 160, 220)
    .icon-jianhao
      display: inline-block
      padding: 3px
      line-height: 30px
      font-size: 30px
      border 4px solid $green
      color $green
      font-weight 600
      border-radius 50%
      &.move-enter-active, &.move-leave-active
        transition all .5s
      &.move-enter, &.move-leave-to
        opacity 0
        transform translateX(15px) rotate(180deg)
    .cart-count
      display: inline-block
      vertical-align: top
      width: 60px
      color #423c3c
      padding-top: 12px
      line-height: 24px
      text-align: center
      font-size: 26px
    .icon-hao
      display:  inline-block
      padding: 6px
      line-height: 30px
      font-size: 30px
      background  $green
      color white
      border-radius 50%
</style>
